package com.loop.homework;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Works {
    public static void main(String[] args) throws ParseException {
        //question1();
        System.out.println(checkTime());
    }

    public static void question1(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请录入数组大小(即数组中可以存储的数据个数)：");
        String str = scanner.next();
        try {
            int n = Integer.parseInt(str);
            if (n < 1){
                System.out.println("你输入数组大小不规范！");
                question1();
            }
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                System.out.println("请输入数字");
                String strNum = scanner.next();
                if ("end".equals(strNum)){
                    break;
                }
                int num = Integer.parseInt(strNum);
                arr[i]=num;
            }
            System.out.print("数组中元素为:"+Arrays.toString(arr));
            Arrays.sort(arr);
            System.out.println(" ,最大值为"+ arr[arr.length-1]);
        }catch (NumberFormatException e){
            System.out.println("请输入数字或end！");
            question1();
        }
    }


    public static boolean checkTime() throws ParseException {
        String start = "2021-5-12";
        String end = "2021-5-18";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date beginTime = simpleDateFormat.parse(start);
        Date endTime = simpleDateFormat.parse(end);

        //开始时间不大于结束时间以及结束时间不大于当前时间
        if (endTime.getTime() > new Date().getTime() || beginTime.getTime()>endTime.getTime()){
            return false;
        }
        Calendar c1 = Calendar.getInstance();
        c1.setTime(beginTime);
        //将起始时间加上3个月
        c1.add(Calendar.MONTH,3);
        beginTime=c1.getTime();
        //若起始时间加上三个月之后的时间还是小于结束时间，那么超过了3个月
        if (beginTime.getTime()<endTime.getTime()){
            return false;
        }
        return true;
    }
}
